﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NuaTarDoneng.Tail
{
    /// <summary>
    /// Message 的摘要说明
    /// </summary>
    public class Message : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string result = "ER";
            string action=context.Request.QueryString["action"];
            if (null != context.Session["uid"])
            {
                Logs.Log(context, context.Session["uid"].ToString() + ":" + action);
            }
            else
            {
                Logs.Log(context, action);
            }
            string uid = context.Session["uid"].ToString();
            
            if (action == "getMessages")
            {
                result = context.Application["Message" + uid].ToString();
            }
            else if (action == "sendMessage" && null!=context.Application["Status" + uid])
            {
                string info = SecurityMan.Decodes(tailSql.getKey(uid), context.Request.QueryString["info"].ToString());
                string oldM = context.Application["Status" + uid].ToString();
                context.Application["Status" + uid] = oldM + "#" + uid + "," +info+ "*";
            }
            context.Response.Write(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}